<div id="good_panel">
    <table class="table table-condensed table-bordered table-striped table-hover text-center">
        <tr>
            <th style="text-align: center">编号</th>
            <th style="text-align: center">套餐类型</th>
            <th style="text-align: center">套餐名称</th>
            <th style="text-align: center">费用</th>
            <th style="text-align: center">优惠1</th>
            <th style="text-align: center">优惠2</th>
            <th style="text-align: center">是否启用</th>
            <th style="text-align: center">操作</th>
        </tr>
        <volist name="list" id="item">
            <tr>
                <td>{$item['id']}</td>
                <td>{$item['class_name']}</td>
                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['name']}</td>
                <td>{$item['price']}</td>
                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['nice1']}</td>
                <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['nice2']}</td>
                <td>{$item['status']?'激活':'失效'}</td>
                <td>
                    <input type="button" name="good_edit" class="btn btn-info" value="编辑">
                    <input type="button" name="good_delete" class="btn btn-danger" value="删除">
                </td>
            </tr>
        </volist>
    </table>
</div>
<div>
    <input type="button" id="good_add" value="添加套餐">
</div>
<script>
    //编辑
    $(document).ready(function () {
        $("input[name='good_edit']").click(function () {
            var obj = $(this).parent().parent();
            var id = obj.children("td:first-child").text();
            console.log('id:'+id);
            $.ajax({
                url: '/admin.php/Good/getSingleGood/goodId/'+id,
                dataType:'json',
                method:'get',
                success: function (res) {
                    if (res.code == 200) {
                        console.log('success');
                        $('#good_panel').empty();
                        $('#good_panel').append(res.data);
                    }
                }
            });
        });
    });

    //添加套餐
    $(document).ready(function () {
        $("#good_add").click(function () {
            console.log('good add');
            $.ajax({
                url: "/admin.php/Good/preAddGood",
                dataType: 'json',
                success: function (res) {
                    if (res.code == 200) {
                        console.log('success');
                        $("#good_panel").empty();
                        $("#good_panel").append(res.data);
                    }
                }
            });
        });
    });

    //删除套餐
    $(document).ready(function () {
        $("input[name='good_delete]").click(function () {
            var obj = $(this).parent().parent();
            var id = obj.children("td:first-child").text();
            console.log('id: '+id);
        });
    });
</script>